package ar.edu.unlu.sistemas.p2p.business.msg;

import org.jdom.Document;
import org.jdom.Element;

public class PeerConnectionACKMessage extends Message {
	
	public static final String TAG_PEER_NAME = "name";
	public static final String TAG_PEER_ID = "peer_id";
	private String peerName;
	private String peerId;
	
	public String getPeerId() {
		return peerId;
	}

	public void setPeerId(String peerId) {
		this.peerId = peerId;
	}

	public PeerConnectionACKMessage(Document xmlDoc) {
		super(xmlDoc);
		// TODO Auto-generated constructor stub
	}

	public PeerConnectionACKMessage() {
		super(MessageFactory.CODE_CONNECT_PEER_NODE_ACK);
	}
	
	protected PeerConnectionACKMessage(int code) {
		super(code);
	}
	
	public String getPeerName() {
		return peerName;
	}

	public void setPeerName(String peerName) {
		this.peerName = peerName;
	}
	
	public Element toXMLElement() {
		Element root = super.toXMLElement();
		root.addContent(new Element(TAG_PEER_NAME).setText(this.getPeerName()));
		root.addContent(new Element(TAG_PEER_ID).setText(this.getPeerId()));
		return root;
	}
	
	protected Element buildFromXMLDoc(Document xmlDoc) {
		Element root = super.buildFromXMLDoc(xmlDoc);
		this.setPeerName(root.getChildText(TAG_PEER_NAME));
		this.setPeerId(root.getChildText(TAG_PEER_ID));
		return root;
	}

}
